//index.js
//获取应用实例
var page = undefined;

const config = require('../../config.js')

Page({
  data: {
    scrollHeight:"",
    xx: true,
    inter: "",
    lighth: 0,
    allNeed: 8888,
    stillNeed: 1234,
    precent: " ",
    amount: 0,
    btnIsShow: false,
    categorys:[],
    goods:[],
    showTab:0
  },

  chooseCategory: function (e) {
    var that = this;
    var categoryId = e.currentTarget.dataset.id;
    that.setData({ "showTab": categoryId});
    wx.request({
      url: config.requestUrl+'/goods/findGoods',
      data: { "categoryId": categoryId},
      success(res) {
        that.setData({ "goods": res.data });
      }
    });
  },
  joinCart: function (e) {
    var productId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/details/details?productId="+productId
    })
  },
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: config.requestUrl +'/goods/findCategory',
      success(res) {
         that.setData({"categorys":res.data});
        that.setData({ "showTab": res.data[0].id});
         wx.request({
           url: config.requestUrl +'/goods/findGoods',
           data:{"categoryId":res.data[0].id},
           success(res){
             that.setData({ "goods": res.data });
             console.log(res.data.length);
           }
         })
      }
    })
    var that = this;
    var amount = wx.getStorageSync('amount');
    if (amount && amount > 0) {
      this.setData({
        amount: amount,
        btnIsShow: true
      })
      wx.removeStorageSync('amount');
    }
    that.setData({
       scrollHeight:  wx.getSystemInfoSync().windowHeight
    })
   
  },
  toDetails:function(){
     wx.navigateTo({
       url: '/pages/details/details',
     })
  },
})


